package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.CartInfoHandler;
import com.cungmua.app.model.request.CartInfoRequest;
import com.cungmua.app.model.response.CartInfoResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 6/25/14.
 */
public class CartInfoTask extends AuthenticatedTask<CartInfoRequest, Void, CartInfoResponse>{
    private final Context context;
    private final CartInfoHandler handler;

    public CartInfoTask(Context context, CartInfoHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected CartInfoResponse doInBackground() throws RetrofitError {
        CartInfoRequest request = params[0];

        return service.getCartInfo(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(CartInfoResponse cartInfoResponse) {
        handler.onCartInfoReceived(cartInfoResponse);
    }
}
